package com.ai.zhly.service;

import java.io.IOException;
import java.sql.Blob;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.ai.dmc.index.base.impl.base.BaseServiceImpl;
import com.ai.dmc.index.common.InitParam;
import com.ai.dmc.index.common.bean.AreaBean;
import com.ai.dmc.index.common.bean.CommonBaseBean;
import com.ai.dmc.index.common.bean.ExportBean;
import com.ai.dmc.index.common.bean.SceneMonitorBean;
import com.ai.dmc.index.common.bean.SmsBean;
import com.ai.dmc.index.common.cache.AreaCache;
import com.ai.dmc.index.common.exception.BusinessException;
import com.ai.dmc.index.common.util.DateUtil;
import com.ai.dmc.utils.json.JsonUtil;
import com.ai.frame.bean.InputObject;
import com.ai.frame.bean.OutputObject;
import com.ai.frame.logger.Logger;
import com.ai.frame.logger.LoggerFactory;
import com.ai.zhly.util.Base64ImgUtil;
//import com.ai.zhly.util.Base64ImgUtil;
import com.ai.zhly.util.DBSequence;
import com.ai.zhly.util.sms.client.SPClient;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import com.ai.dmc.index.common.InitParam;

/**
 * 
 * @Title: MapDataImpl.java
 * @Description: 家装宽带展示层service
 * @author xueyf3
 * @date 2016年5月23日 下午4:22:54 Copyright：Copyright (c) 2016
 *       Company：北京亚信智慧数据科技有限公司
 * @version V1.0
 */
public class SceneMonitorServiceImpl extends BaseServiceImpl
		implements ISceneMonitorService {
	// 定义对应Mapper文件的命名空间
	private static final String NAMESPACE = "SceneMonitor.";
	public final static String SMS_SEND_SUCCESS = "1"; // 短信发送：成功
	public final static String SMS_SEND_FAIL = "0"; // 短信发送：失败

	public static Logger log = LoggerFactory
			.getServiceLog(SceneMonitorServiceImpl.class);

	private ICommonService commonService;
	private ILogService logService;

	public void setCommonService(ICommonService commonService) {
		this.commonService = commonService;
	}

	public void setLogService(ILogService logService) {
		this.logService = logService;
	}
	
	/** 
     * 16进制字符串转换为字符串 
     *  
     * @param s 
     * @return 
     */  
    public static String hexStringToString(String s) {  
        if (s == null || s.equals("")) {  
            return null;  
        }  
        s = s.replace(" ", "");  
        byte[] baKeyword = new byte[s.length() / 2];  
        for (int i = 0; i < baKeyword.length; i++) {  
            try {  
                baKeyword[i] = (byte) (0xff & Integer.parseInt(  
                        s.substring(i * 2, i * 2 + 2), 16));  
            } catch (Exception e) {  
                e.printStackTrace();  
            }  
        }  
        try {  
            s = new String(baKeyword, "gbk");  
            new String();  
        } catch (Exception e1) {  
            e1.printStackTrace();  
        }  
        return s;  
    }
	
	/**
	 * BLOB字段转String
	 * 
	 * @param blob
	 * @return
	 * @throws SQLException
	 */
	private String blob2Str(Blob blob) throws SQLException {
		StringBuffer result = null;
		try {
			if (null == blob || blob.length() < 1) {
				return null;
			}
			result = new StringBuffer();
			int i = 1;
			int cacheSize = 2048000;
			while (i < blob.length()) {
				result.append(new String(blob.getBytes(i, cacheSize)));
				i += cacheSize;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return result.toString();
	}

	/**
	 * 景区排行top10
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	@Override
	public void queryRegionTop10(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		String userId = inputObject.getParams().get("userId");
		List<CommonBaseBean> rList = new ArrayList<>();
		List<CommonBaseBean> allList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionPersonCnts", inputObject.getParams(),
				CommonBaseBean.class);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> rl = new ArrayList<JSONObject>();
		// 权限过滤
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> scopeList = scopeMap.get(AreaBean.TYPE_ALL);
		for (int i = 0; i < allList.size() && rList.size() < 10; i++) {
			String regionId = allList.get(i).getQuery_value2();
			for (String aId : scopeList) {
				if (regionId.startsWith(aId)) {
					allList.get(i)
							.setQuery_value1(String.valueOf(rList.size() + 1));
					rList.add(allList.get(i));
					break;
				}
			}
		}
		if (rList != null && rList.size() > 0) {
			CommonBaseBean bean = null;
			for (int i = 0; i < rList.size(); i++) {
				bean = rList.get(i);
				String areaId = bean.getQuery_value2();
				String areaName = bean.getQuery_value3();
				String stayPersonCnts = bean.getQuery_value4();
				String hisAvgVstCnts = bean.getQuery_value5();
				JSONObject tmpObj = new JSONObject();
				tmpObj.put("orderId", i + 1);
				tmpObj.put("areaId", areaId);
				tmpObj.put("areaName", areaName);
				tmpObj.put("stayPersonCnts", stayPersonCnts);
				tmpObj.put("hisAvgVstCnts", hisAvgVstCnts);
				rl.add(tmpObj);
			}
		}

		resultMap.put("regions", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}


	/**
	 * 
	 * @Description : 查询仪表盘数据
	 * @return void
	 * 
	 * @author : pengjy
	 * @date : 2015年11月10日 下午4:43:20
	 * 
	 */
	@Override
	public void queryGauge(InputObject inputObject, OutputObject outputObject) throws BusinessException {
		
		List<JSONObject> rl = new ArrayList<JSONObject>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String cityId = inputObject.getParams().get("cityId");
		String userId = inputObject.getParams().get("userId");
		if (cityId == null || cityId.equals("")) {
			cityId = "all";
			inputObject.getParams().put("cityId","all");
		}
		Map<String, List<String>> scopeMap = commonService.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		String citys = "";
		if (cityId == null || cityId.equals("all")) {
			for (int i = 0; i < allList.size(); i++) {
				citys += "'" + allList.get(i) + "',";
			}
			citys = citys.substring(0, citys.length() - 1);
		} else {
			for (int i = 0; i < allList.size(); i++) {
				if (cityId.equals(allList.get(i))) {
					citys = "'" + cityId + "'";
					break;
				}
			}
			if (citys==null||citys.trim().equals("")) {
				cityId = "'-1'";
				citys = "'-1'";
			}
		}
		inputObject.getParams().put("cityId", cityId);
		inputObject.getParams().put("cityIdList", citys);

		List<CommonBaseBean> rList = this.getBaseDao().queryForList(
                NAMESPACE + "queryGauge", inputObject.getParams(),CommonBaseBean.class);
		if (rList != null && rList.size() > 0) {
			for (CommonBaseBean bean : rList) {
				String areaId = bean.getQuery_value1();
				String areaName = bean.getQuery_value2();
				String stayPersonCnts = bean.getQuery_value3();
				String sumVstCnts = bean.getQuery_value4();
				JSONObject tmpObj = new JSONObject();
				tmpObj.put("areaId", areaId);
				tmpObj.put("areaName", areaName);
				tmpObj.put("stayPersonCnts", stayPersonCnts);
				tmpObj.put("sumVstCnts", sumVstCnts);
				rl.add(tmpObj);
			}
		}
		resultMap.put("gaugeDate",null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 询景区按地市分组前N个
	 * @return void
	 * 
	 * @author : pengjy
	 * @date : 2015年11月10日 下午4:43:20
	 * 
	 */
	@Override
	public void queryRegionTopByCity(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		String userId = inputObject.getParams().get("userId");
		int topNum = 2;
		String topNumStr = inputObject.getParams().get("topNum");
		if (topNumStr != null && topNumStr.matches("[0-9]+")) {
			topNum = Integer.valueOf(topNumStr);
		}
		List<JSONObject> rl = new ArrayList<JSONObject>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> tList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionTopByCity", inputObject.getParams(),
				CommonBaseBean.class);
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		// 权限过滤
		if (tList == null) {
			tList = new ArrayList<CommonBaseBean>();
		}
		for (int i = 0; i < tList.size(); i++) {
			String regionId = tList.get(i).getQuery_value2();
			for (String aId : allList) {
				if (regionId.startsWith(aId)) {
					if (!checkByTopNum(rList, tList.get(i),topNum)) {
						break;
					}
					rList.add(tList.get(i));
					break;
				}
			}
		}
		if (rList != null && rList.size() > 0) {
			for (CommonBaseBean bean : rList) {
				String upId = bean.getQuery_value1();
				String areaId = bean.getQuery_value2();
				String areaName = bean.getQuery_value3();
				String lng = bean.getQuery_value5();
				String lat = bean.getQuery_value6();
				String warnLevelId = bean.getQuery_value7();
				String stayPersonCnts = bean.getQuery_value8();
				String sumVstCnts = bean.getQuery_value9();
				String _regionType = bean.getQuery_value10();
				JSONObject tmpObj = new JSONObject();
				tmpObj.put("cityId", upId);
				tmpObj.put("areaId", areaId);
				tmpObj.put("areaName", areaName);
				tmpObj.put("lng", lng);
				tmpObj.put("lat", lat);
				tmpObj.put("warnLevelId", warnLevelId);
				tmpObj.put("stayPersonCnts", stayPersonCnts);
				tmpObj.put("sumVstCnts", sumVstCnts);
				tmpObj.put("regionType", _regionType);
				rl.add(tmpObj);
			}
		}
		resultMap.put("data", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}
	
	/**
	 * 
	 * @Description : 判定结果中单个地市中是否已满topNum个区域
	 * @return void
	 * 
	 * @author : pengjy
	 * @date : 2015年11月10日 下午4:43:20
	 * 
	 */
	private boolean checkByTopNum(List<CommonBaseBean> rList,CommonBaseBean region,int topNum){
		String cityId = region.getQuery_value1();
		int num = 0;
		for (int i = 0; i < rList.size(); i++) {
			if (rList.get(i)!=null &&cityId!=null&& cityId.equals(rList.get(i).getQuery_value1())) {
				num++;
			}
		}
		
		return num<topNum;
	}

	/**
	 * 
	 * @Description : 首页预警信息展示，根据地市查询，无地市条件时查询全省
	 * @return void
	 * 
	 * @author : pengjy
	 * @date : 2015年11月10日 下午4:43:20
	 * 
	 */
	@Override
	public void queryWarnByCity(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		String userId = inputObject.getParams().get("userId");
		List<JSONObject> rl = new ArrayList<JSONObject>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<>();
		List<CommonBaseBean> allList = this.getBaseDao().queryForList(
				NAMESPACE + "queryWarnByCity", inputObject.getParams(),
				CommonBaseBean.class);
		if (rList == null) {
			rList = new ArrayList<CommonBaseBean>();
		}
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> scopeList = scopeMap.get(AreaBean.TYPE_ALL);
		for (int i = 0; i < allList.size() && allList.size() < 10; i++) {
			String regionId = allList.get(i).getQuery_value3();
			for (String aId : scopeList) {
				if (regionId.startsWith(aId)) {
					rList.add(allList.get(i));
					break;
				}
			}
		}

		if (rList != null && rList.size() > 0) {
			for (CommonBaseBean bean : rList) {
				String areaId = bean.getQuery_value3();
				String areaName = bean.getQuery_value4();
				String warnLevelId = bean.getQuery_value5();
				String stayPersonCnts = bean.getQuery_value6();
				String warnId = bean.getQuery_value7();
				JSONObject tmpObj = new JSONObject();
				tmpObj.put("areaId", areaId);
				tmpObj.put("areaName", areaName);
				tmpObj.put("warnLevelId", warnLevelId);
				tmpObj.put("stayPersonCnts", stayPersonCnts);
				tmpObj.put("warnId", warnId);
				rl.add(tmpObj);
			}
		}
		resultMap.put("data", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 获取字符串的长度，如果有中文，则每个中文字符计为2位
	 * 
	 * @param value
	 *            指定的字符串
	 * @return 字符串的长度
	 * @author likun
	 */
	private int length(String value) {
		int valueLength = 0;
		String chinese = "[\u0391-\uFFE5]";
		/* 获取字段值的长度，如果含中文字符，则每个中文字符长度为2，否则为1 */
		for (int i = 0; i < value.length(); i++) {
			/* 获取一个字符 */
			String temp = value.substring(i, i + 1);
			/* 判断是否为中文字符 */
			if (temp.matches(chinese)) {
				/* 中文字符长度为2 */
				valueLength += 2;
			} else {
				/* 其他字符长度为1 */
				valueLength += 1;
			}
		}
		return valueLength;
	}

	/**
	 * 
	 * @Description :新增景区短信人群
	 * 
	 * @return Boolean
	 *
	 * @author : pengjy
	 * @date : 2015年12月21日 下午1:59:47
	 *
	 */
	@Override
	public void insertRegionManager(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		// 0 成功；1 失败；2已存在；3 备注长度过长
		String flag = "1";
		// 插入数据
		boolean exist = false;
		// 先查询是否已存在
		List<CommonBaseBean> rList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionManager", inputObject.getParams(),
				CommonBaseBean.class);
		String managerPhone = inputObject.getParams().get("phone");
		for (CommonBaseBean bean : rList) {
			if (bean.getQuery_value2() != null
					&& bean.getQuery_value2().indexOf(managerPhone) > -1) {
				exist = true;
			}
		}
		// 判断是否插入
		if (exist) {
			flag = "2";
		} else {
			int remarkLength = length(inputObject.getParams().get("remark"));
			if (remarkLength > 30) {
				flag = "3";
			} else {
				int num = this.getBaseDao().insert(
						NAMESPACE + "insertRegionManager",
						inputObject.getParams());
				flag = num > 0 ? "0" : "1";
			}
		}

		// resultMap.put("data",null == flag ? "" : JsonUtil.Object2Json(flag));
		outputObject.setObject(flag);
	}

	/**
	 * 
	 * @Description :新增景区短信人群
	 * 
	 * @return Boolean
	 *
	 * @author : pengjy
	 * @date : 2015年12月21日 下午1:59:47
	 *
	 */
	@Override
	public void deleteRegionManager(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		int num = this.getBaseDao().delete(NAMESPACE + "deleteRegionManager",
				inputObject.getParams());
		Boolean flag = num > 0 ? true : false;
		resultMap.put("data", null == flag ? "" : JsonUtil.Object2Json(flag));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * @Description : 景区监控通知处理
	 * 
	 * @return void
	 * 
	 * @author : xuxiong
	 * @date : 2015年11月27日 下午11:07:57
	 * 
	 */
	@Override
	public void infoDealByRegionId(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String phones = inputObject.getParams().get("phones");
		String msgContent = inputObject.getParams().get("msgContent");
		// 1.发送短信
		int sendFlag = this.sendSms(phones, msgContent);
		resultMap.put("data", JsonUtil.Object2Json(sendFlag));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 加载景区监控数据
	 * @return List<JSONObject>
	 * 
	 * @author : xuxiong
	 * @date : 2015年11月10日 下午4:17:16
	 * 
	 */
	@Override
	public void loadRegionMonitorData(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> jList = new ArrayList<JSONObject>();
		List<CommonBaseBean> cList = this.getBaseDao().queryForList(
				NAMESPACE + "loadRegionMonitorData", inputObject.getParams(),
				CommonBaseBean.class);
		if (null == cList || cList.size() == 0) {
			cList = new ArrayList<CommonBaseBean>();
		}

		// 拼接json
		for (CommonBaseBean bean : cList) {
			JSONObject j = new JSONObject();

			String regionId = bean.getQuery_value1();
			String regionName = bean.getQuery_value2();
			String levelId = bean.getQuery_value3();
			String cnt = bean.getQuery_value4();
			String regionType = bean.getQuery_value5();
			String cityId = bean.getQuery_value6();

			j.put("regionId", regionId);
			j.put("regionName", regionName);
			j.put("regionType", regionType);
			j.put("levelId", levelId);
			j.put("cnt", cnt);
			j.put("cityId", cityId);

			jList.add(j);
		}
		resultMap.put("data", null == jList ? "" : JsonUtil.Object2Json(jList));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 查询某个景区实时客流量和累计量
	 * @return void
	 * 
	 * @author : xuxiong
	 * @date : 2015年11月13日 上午10:11:28
	 * 
	 */
	@Override
	public void loadRegionMouseOverData(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> jList = new ArrayList<JSONObject>();
		List<CommonBaseBean> cList = this.getBaseDao().queryForList(
				NAMESPACE + "loadRegionMouseOverData", inputObject.getParams(),
				CommonBaseBean.class);
		if (null == cList || cList.size() == 0) {
			cList = new ArrayList<CommonBaseBean>();
		}

		// 拼接json
		for (CommonBaseBean bean : cList) {
			JSONObject j = new JSONObject();

			String _regionId = bean.getQuery_value1();
			String stayPersonCnts = bean.getQuery_value2();
			String sumVstVnts = bean.getQuery_value3();

			j.put("regionId", _regionId);
			j.put("stayCnts", stayPersonCnts);
			j.put("sumCnts", sumVstVnts);

			jList.add(j);
		}
		resultMap.put("data", null == jList ? "" : JsonUtil.Object2Json(jList));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	/**
	 * @Description : 查询景区管理人员手机号码
	 * 
	 * @return List<CommonBaseBean>
	 *
	 * @author : xuxiong
	 * @date : 2015年12月17日 上午11:17:31
	 * 
	 */
	@Override
	public void queryGroupByCondition(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		JSONArray result = new JSONArray();
		List<CommonBaseBean> tmpList = new ArrayList<CommonBaseBean>();
		List<CommonBaseBean> rList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionManager", inputObject.getParams(),
				CommonBaseBean.class);
		if (rList == null) {
			rList = new ArrayList<CommonBaseBean>();
		}
		// 过滤号码
		String managerPhone = inputObject.getParams().get("phone");
		if (managerPhone != null && !managerPhone.equals("") && rList != null
				&& rList.size() > 0) {
			tmpList.clear();
			for (CommonBaseBean bean : rList) {
				if (bean.getQuery_value2() != null
						&& bean.getQuery_value2().indexOf(managerPhone) > -1) {
					tmpList.add(bean);
				}
			}
			rList.clear();
			rList.addAll(tmpList);
			tmpList.clear();
		}
		// 过滤姓名
		String managerName = inputObject.getParams().get("name");
		if (managerName != null && !managerName.equals("") && rList != null
				&& rList.size() > 0) {
			tmpList.clear();
			for (CommonBaseBean bean : rList) {
				if (bean.getQuery_value1() != null
						&& bean.getQuery_value1().indexOf(managerName) > -1) {
					tmpList.add(bean);
				}
			}
			rList.clear();
			rList.addAll(tmpList);
			tmpList.clear();
		}
		JSONObject obj = new JSONObject();
		CommonBaseBean bean = null;
		if (null != rList && !rList.isEmpty()) {
			for (int i = 0; i < rList.size(); i++) {
				bean = rList.get(i);
				obj.put("manager_name", bean.getQuery_value1());
				obj.put("manager_phone", bean.getQuery_value2());
				obj.put("region_id", bean.getQuery_value3());
				obj.put("region_name", bean.getQuery_value4());
				obj.put("remark", bean.getQuery_value5());
				result.add(obj);
			}
		}
		resultMap.put("data", null == result ? "" : result);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 预警处理，信息查询
	 * @return void
	 * 
	 * @author : pengjy
	 * @throws ParseException
	 * @date : 2015年11月10日 下午4:43:20
	 * 
	 */
	@Override
	public void queryGroupWarnDealInfoById(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String msgContent = "";
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		String userId = inputObject.getParams().get("userId");
		String regionId = "";
		try {
			rList = this.queryWarnDealInfoByIdData(userId,
					inputObject.getParams());
		} catch (ParseException e) {
			e.printStackTrace();
		}

		if (rList != null && rList.size() > 0) {
			for (CommonBaseBean bean : rList) {
				String warnLevel = bean.getQuery_value1();
				String time = bean.getQuery_value2();
				regionId = bean.getQuery_value3();
				String regionName = bean.getQuery_value4();
				String stayPersonCnts = bean.getQuery_value5();
				String level = bean.getQuery_value7();
				// 查询该预警级别的自定义模板
				CommonBaseBean smsFormWork = this.getSmsFormWork(regionId,
						level);
				if (smsFormWork != null) {
					msgContent = smsFormWork.getQuery_value2();
					msgContent = msgContent.replace("<景区名称>", regionName);
					msgContent = msgContent.replace("<时间>", time);
					msgContent = msgContent.replace("<人数>", stayPersonCnts);
				} else {
					if ("红色".equals(warnLevel)) {
						msgContent = warnLevel + "告警：【" + regionName + "】景区，"
								+ time + "游客数达到" + stayPersonCnts
								+ "人，请限制景区客流量。";
					} else if ("橙色".equals(warnLevel)) {
						msgContent = warnLevel + "预警：【" + regionName + "】景区，"
								+ time + "游客数达到" + stayPersonCnts
								+ "人，请提前做好景区客流量控制。";
					} else {
						msgContent = warnLevel + "预警：【" + regionName + "】景区，"
								+ time + "游客数达到" + stayPersonCnts
								+ "人，请密切关注景区客流量。";
					}
				}

			}
		}
		resultMap.put("result", null == msgContent ? "" : msgContent);
		// 查询产生预警景区管理人员号码
		List<CommonBaseBean> managerInfoList = this
				.queryRegionManager(regionId);
		List<JSONObject> result = new ArrayList<JSONObject>();
		JSONObject tmpObj = new JSONObject();
		tmpObj.put("size", managerInfoList.size());
		result.add(tmpObj);
		resultMap.put("managerInfo", null == result ? "" : result);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * @Description : 查询景区管理人员手机号码
	 * 
	 * @return List<CommonBaseBean>
	 *
	 * @author : xuxiong
	 * @date : 2015年12月17日 上午11:20:43
	 * 
	 */
	@Override
	public List<CommonBaseBean> queryRegionManager(String regionId) {

		Map<String, String> param = new HashMap<String, String>();
		param.put("regionId", regionId);
		List<CommonBaseBean> rList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionManager", param, CommonBaseBean.class);
		if (rList == null) {
			rList = new ArrayList<CommonBaseBean>();
		}

		return rList;
	}

	/**
	 * @Description : 查询子区域数据
	 * 
	 * @return void
	 * 
	 * @author : menxl
	 * @date : 2015-11-14 上午9:49:10
	 * 
	 */
	@Override
	public void querySubRegionInfo(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String regionId = inputObject.getParams().get("regionId");
		Map<String, Map<String, AreaBean>> allMap = commonService
				.queryAreaMap();

		Map<String, AreaBean> regionMap = allMap.get("region");
		Map<String, AreaBean> areaMap = allMap.get("city");
		AreaBean regionBean = regionMap.get(regionId);
		AreaBean areaBean = areaMap.get(regionBean.getUpperId());
		regionBean.setUpperName(areaBean.getAreaName());
		resultMap.put("data", null == regionBean ? "" : regionBean.toJSON());
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * @Description : 查询区域预警信息
	 * 
	 * @return void
	 * 
	 * @author : menxl
	 * @throws ParseException
	 * @date : 2015-11-14 上午9:50:13
	 * 
	 */
	@Override
	public void querySubRegionWarn(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String userId = inputObject.getParams().get("userId");
		String regionId = inputObject.getParams().get("regionId");
		// 查询区域监控信息
		List<SceneMonitorBean> rList = this.getBaseDao().queryForList(
				NAMESPACE + "querySubRegionFlow", inputObject.getParams(),
				SceneMonitorBean.class);
		// 查询区域预警数据
		List<SceneMonitorBean> wList = this.getBaseDao().queryForList(
				NAMESPACE + "querySubRegionWarn", inputObject.getParams(),
				SceneMonitorBean.class);

		Map<String, SceneMonitorBean> wMap = new HashMap<String, SceneMonitorBean>();
		if (null != wList && !wList.isEmpty()) {
			for (SceneMonitorBean tmpBean : wList) {
				wMap.put(tmpBean.getRegionId(), tmpBean);
			}
		}

		if (null != rList && !rList.isEmpty()) {
			SceneMonitorBean wBean = new SceneMonitorBean();
			for (SceneMonitorBean tmpBean : rList) {
				wBean = wMap.get(tmpBean.getRegionId());
				if (null != wBean) {
					tmpBean.setWarnLevelId(wBean.getWarnLevelId());
					tmpBean.setWarnLevelName(wBean.getWarnLevelName());
					tmpBean.setWarnId(wBean.getWarnId());
					tmpBean.setDealTypeId(wBean.getDealTypeId());
				}
			}
		}

		if (null != rList && !rList.isEmpty()) {

			SceneMonitorBean sceneBean = rList.get(0);

			// 预警处理,信息组织需要内容
			String warnId = sceneBean.getWarnId();
			Map<String, String> params = new HashMap<String, String>();
			params.put("warnId", warnId);
			List<CommonBaseBean> wList2 = new ArrayList<CommonBaseBean>();
			try {
				if (warnId !=null && !warnId.equals("")) {
					wList2 = this.queryWarnDealInfoByIdData(userId, params);
				}
			} catch (ParseException e) {
				e.printStackTrace();
			}
			if (rList != null && rList.size() > 0) {
				JSONObject tmpObj = new JSONObject();
				for (CommonBaseBean bean : wList2) {
					String warnLevel = bean.getQuery_value1();
					String time = bean.getQuery_value2();
					String regionName = bean.getQuery_value4();
					String stayPersonCnts = bean.getQuery_value5();
					tmpObj.put("warnLevel", warnLevel);
					tmpObj.put("regionId", regionId);
					tmpObj.put("time", time);
					tmpObj.put("regionName", regionName);
					tmpObj.put("stayPersonCnts", stayPersonCnts);
				}

				// 查询产生预警景区管理人员号码
				List<CommonBaseBean> managerInfoList = this
						.queryRegionManager(regionId);
				List<JSONObject> managerInfoJson = new ArrayList<JSONObject>();
				if (managerInfoList != null && managerInfoList.size() > 0) {
					for (CommonBaseBean bean : managerInfoList) {
						JSONObject info = new JSONObject();
						info.put("name", bean.getQuery_value1());
						info.put("phone", bean.getQuery_value2());
						managerInfoJson.add(info);
					}
				}
				tmpObj.put("managerInfo", managerInfoJson);
				resultMap.put("warnInfo", tmpObj);
			}

			String dealFlag = sceneBean.getDealTypeId();
			if (null != dealFlag && "1".equals(dealFlag)) {
				List<JSONObject> dList = this.queryDealListByWarnId(warnId);
				resultMap.put("dealList", dList);
			}
		} else {
			SceneMonitorBean sBean = new SceneMonitorBean();
			sBean.setRegionId(regionId);
			sBean.setStayPersonCnts("0");
			sBean.setSumVstCnts("0");
			rList.add(sBean);
		}

		resultMap.put("result",
				null == rList ? "" : JsonUtil.Object2Json(rList));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	/**
	 * 
	 * @Description : 预警处理，信息查询
	 * @return void
	 * 
	 * @author : pengjy,xueyf3
	 * @throws ParseException
	 * @date : 2015年11月10日 下午4:43:20
	 * @updatedate : 2016年1月5日 下午2:52:12
	 * 
	 */
	@Override
	public void queryWarnDealInfoById(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String userId = inputObject.getParams().get("userId");
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		try {
			rList = this.queryWarnDealInfoByIdData(userId,
					inputObject.getParams());
		} catch (ParseException e) {
			e.printStackTrace();
		}
		String regionId = "";
		String msgContent = "";
		if (rList != null && rList.size() > 0) {
			CommonBaseBean bean = rList.get(0);
			String warnLevel = bean.getQuery_value1();
			String time = bean.getQuery_value2();
			regionId = bean.getQuery_value3();
			String regionName = bean.getQuery_value4();
			String stayPersonCnts = bean.getQuery_value5();
			String level = bean.getQuery_value7();
			// 查询该预警级别的自定义模板
			CommonBaseBean smsFormWork = this.getSmsFormWork(regionId, level);
			if (smsFormWork != null) {
				msgContent = smsFormWork.getQuery_value2();
				msgContent = msgContent.replace("<景区名称>", regionName);
				msgContent = msgContent.replace("<时间>", time);
				msgContent = msgContent.replace("<人数>", stayPersonCnts);
			} else {
				if ("红色".equals(warnLevel)) {
					msgContent = warnLevel + "告警：【" + regionName + "】景区，" + time
							+ "游客数达到" + stayPersonCnts + "人，请限制景区客流量。";
				} else if ("橙色".equals(warnLevel)) {
					msgContent = warnLevel + "预警：【" + regionName + "】景区，" + time
							+ "游客数达到" + stayPersonCnts + "人，请提前做好景区客流量控制。";
				} else {
					msgContent = warnLevel + "预警：【" + regionName + "】景区，" + time
							+ "游客数达到" + stayPersonCnts + "人，请密切关注景区客流量。";
				}
			}

		}
		resultMap.put("result", null == msgContent ? "" : msgContent);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 预警短信内容管理
	 * 
	 * @return void
	 *
	 * @author : tanxc
	 * @date : 2016-1-5 下午2:40:29
	 *
	 */
	@Override
	public void regionPhoneConfQuery(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		JSONArray result = new JSONArray();
		List<CommonBaseBean> rList = this.getBaseDao().queryForList(
				NAMESPACE + "regionPhoneConfQuery", inputObject.getParams(),
				CommonBaseBean.class);
		JSONObject obj = new JSONObject();
		CommonBaseBean bean = null;
		if (null != rList && !rList.isEmpty()) {
			// 先将最大承载量取出来
			for (int i = 0; i < rList.size(); i++) {
				bean = rList.get(i);
				// 判断预警类型
				if (InitParam.WARN_RED_NUM.equals(bean.getQuery_value1())) {
					obj.put("warn_name", "红色预警");
				} else if (InitParam.WARN_YELLOW_NUM.equals(bean.getQuery_value1())) {
					obj.put("warn_name", "黄色预警");
				} else {
					obj.put("warn_name", "橙色预警");
				}
				obj.put("warn_level", bean.getQuery_value1());
				obj.put("warn_content", bean.getQuery_value2());
				obj.put("is_open", bean.getQuery_value3());
				obj.put("id", bean.getQuery_value4());
				obj.put("region_id", bean.getQuery_value5());
				result.add(obj);
			}
		}
		resultMap.put("result", null == result ? "" : result);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 预警短信内容更新
	 * 
	 * @return void
	 *
	 * @author : tanxc
	 * @date : 2016-1-5 下午5:56:06
	 *
	 */
	@Override
	public void regionPhoneConfUpdate(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		Date time = new Date();
		// 获取当前时间
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String str = format.format(time);
		inputObject.getParams().put("time", str);
		int num = this.getBaseDao().update(NAMESPACE + "regionPhoneConfUpdate",
				inputObject.getParams());
		boolean flag = num > 0 ? true : false;
		resultMap.put("result", flag);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	/**
	 * 
	 * @Description : 查询预警阈值
	 * 
	 * @return void
	 *
	 * @author : tanxc
	 * @date : 2015-12-30 下午5:36:52
	 *
	 */
	@Override
	public void regionWarnConfQuery(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		JSONArray result = new JSONArray();
		List<String> list = new ArrayList<String>();
		List<CommonBaseBean> rList = this.getBaseDao().queryForList(
				NAMESPACE + "regionWarnConfQuery", inputObject.getParams(),
				CommonBaseBean.class);
		JSONObject obj = new JSONObject();
		CommonBaseBean bean = null;
		CommonBaseBean beanRes = null;
		if (null != rList && !rList.isEmpty()) {
			// 先将最大承载量取出来
			for (int i = 0; i < rList.size(); i++) {
				bean = rList.get(i);
				if (InitParam.WARN_RED_NUM.equals(bean.getQuery_value5())) {
					list.add(bean.getQuery_value1());
				}
			}
			// 依次将红色预警阈值、橘色预警值、黄色预警值添加进去
			for (int j = 0; j < list.size(); j++) {
				for (int k = 0; k < rList.size(); k++) {
					beanRes = rList.get(k);
					if (list.get(j).equals(beanRes.getQuery_value1())) {
						obj.put("region_id", beanRes.getQuery_value1());
						obj.put("region_name", beanRes.getQuery_value2());
						// 类型是红色预警阈值
						if (InitParam.WARN_RED_NUM
								.equals(beanRes.getQuery_value5())) {
							obj.put("region_max", beanRes.getQuery_value3());
							obj.put("red_num", beanRes.getQuery_value4());
						}
						// 类型是橘色预警阈值
						else if (InitParam.WARN_ORANGE_NUM
								.equals(beanRes.getQuery_value5())) {
							obj.put("orange_num", beanRes.getQuery_value4());
						}
						// 类型是橘色预警阈值
						else if (InitParam.WARN_YELLOW_NUM
								.equals(beanRes.getQuery_value5())) {
							obj.put("yellow_num", beanRes.getQuery_value4());
						}
					}
				}
				result.add(obj);
				obj.clear();
			}
		}
		resultMap.put("result", null == result ? "" : result);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * @Description : 更新预警阈值设置
	 * 
	 * @return void
	 *
	 * @author : tanxc
	 * @date : 2016-1-4 下午4:36:35
	 *
	 */
	@Override
	public void regionWarnConfUpdate(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		Date time = new Date();
		// 获取当前时间
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		String str = format.format(time);
		inputObject.getParams().put("time", str);
		try {
			this.getBaseDao().update(NAMESPACE + "regionWarnConfDelete",
					inputObject.getParams());
			this.getBaseDao().update(NAMESPACE + "regionWarnConfUpdateRed",
					inputObject.getParams());
			this.getBaseDao().update(NAMESPACE + "regionWarnConfUpdateOra",
					inputObject.getParams());
			this.getBaseDao().update(NAMESPACE + "regionWarnConfUpdateYel",
					inputObject.getParams());
		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("result", false);
			outputObject.setObject(JsonUtil.Object2Json(resultMap));
			return;
		}
		resultMap.put("result", true);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * @Description : 预警处理
	 * 
	 * @return void
	 * 
	 * @author : mi
	 * @date : 2015年11月14日 下午11:07:57
	 * 
	 */
	@Override
	public void warnDealById(InputObject inputObject, OutputObject outputObject)
			throws BusinessException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		String warnId = inputObject.getParams().get("warnId");
		String phones = inputObject.getParams().get("phones");
		String msgContent = inputObject.getParams().get("msgContent");
		try {
			// 1.发送短信
			this.sendSms(phones, msgContent);
			// 2.更新预警状态为已处理
			this.getBaseDao().update(NAMESPACE + "updateWarnDealTypeById",
					inputObject.getParams());
			// 3.记录处理日志
			Map<String, String> params2 = new HashMap<String, String>();
			String staffId = inputObject.getParams().get("userId");
			String date = new SimpleDateFormat("yyyyMMddHHmmss")
					.format(new java.util.Date());
			params2.put("warn_id", warnId);
			params2.put("deal_staff_id", staffId);
			params2.put("receive_msisdn", phones);
			params2.put("sms_content", msgContent);
			params2.put("date", date);
			this.insertForWarnSmsMin(params2);

		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("result", false);
			outputObject.setObject(JsonUtil.Object2Json(resultMap));
			return;
		}
		resultMap.put("result", true);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * @Description : 群发预警处理
	 * 
	 * @return void
	 * 
	 * @author : mi
	 * @date : 2015年11月14日 下午11:07:57
	 * 
	 */
	@Override
	public void warnGroupDealById(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String warnId = inputObject.getParams().get("warnId");
		String regionId = inputObject.getParams().get("regionId");
		String msgContent = inputObject.getParams().get("msgContent");
		String userId = inputObject.getParams().get("userId");
		String phones = "";
		try {
			// 1.查询群组所有号码
			List<CommonBaseBean> managerList = this
					.queryRegionManager(regionId);
			// 2.逐一发送短信
			for (int i = 0; i < managerList.size(); i++) {
				CommonBaseBean bean = managerList.get(i);
				String phone = bean.getQuery_value2();
				this.sendSms(phone, msgContent);
				phones += phone + ",";
			}
			// 3.更新预警状态为已处理
			this.getBaseDao().update(NAMESPACE + "updateWarnDealTypeById",
					inputObject.getParams());
			// 4.记录处理日志
			Map<String, String> params2 = new HashMap<String, String>();
			String date = new SimpleDateFormat("yyyyMMddHHmmss")
					.format(new java.util.Date());
			params2.put("warn_id", warnId);
			params2.put("deal_staff_id", userId);
			params2.put("receive_msisdn", phones);
			params2.put("sms_content", msgContent);
			params2.put("date", date);
			this.insertForWarnSmsMin(params2);

		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("result", false);
			outputObject.setObject(JsonUtil.Object2Json(resultMap));
			return;
		}
		resultMap.put("result", true);
		outputObject.setObject(JsonUtil.Object2Json(resultMap));

	}

	/**
	 * @Description : 发送短信
	 * 
	 * @return
	 * 
	 * @author : pengjy
	 * @date : 2015-11-14 上午9:54:27
	 * 
	 */
	public int sendSms(String phones, String msgContent) {
		String[] phoneList = phones.split(",");

		int sendFlag = -1;
		for (int i = 0; i < phoneList.length; i++) {
			// 如果是手机号码，调用短信发送接口（正式下）
			if (InitParam.DEPLOY_TYPE_PRODUCT.equals(InitParam.DEPLOY_TYPE)) {
				sendFlag = sendSmsBySp(phoneList[i], msgContent);
			}
			// 记录日志
			SmsBean smsLog = new SmsBean();
			smsLog.setSmsId(DBSequence.getInstance().getSequence());
			smsLog.setPhone(phoneList[i].trim());
			smsLog.setSmsFlag(sendFlag == 0 ? SMS_SEND_SUCCESS : SMS_SEND_FAIL);
			smsLog.setSmsTime(
					DateUtil.getInstance().getToday("yyyyMMddHHmmss"));
			smsLog.setSmsContent(msgContent);
			try {
				logService.insertSmsLog(smsLog);
			} catch (BusinessException e) {
				e.printStackTrace();
				return sendFlag;
			}
		}

		return sendFlag;
	}

	/**
	 * 发送短信校验，返回标识-1失败，0成功
	 * 
	 * @Description :
	 * 
	 * @return int
	 *
	 * @author : mi
	 * @date : 2015年11月20日 上午10:00:16
	 *
	 */
	private int sendSmsBySp(String phone, String msgContent) {
		int flag = -1;
		SPClient sp = new SPClient();
		if (phone.trim().matches("^[1][34578][0-9]{9}$")) {
			try {
				flag = sp.startSP(phone, msgContent);
			} catch (Exception e) {
				flag = -1;
				return flag;
			}
		}
		return flag;
	}

	/**
	 * 
	 * @Description :查询用户自定义的全部启用状态的短信模板
	 * 
	 * @return List<CommonBaseBean>
	 *
	 * @author : xueyf3
	 * @date : 2016年1月5日 下午3:21:08
	 *
	 */
	public CommonBaseBean getSmsFormWork(String regionId, String warnLevel) {
		// 查询数据
		CommonBaseBean obj = null;
		Map<String, String> map = new HashMap<String, String>();
		map.put("regionId", regionId);
		map.put("warnLevel", warnLevel);
		obj = this.getBaseDao().queryForObject(NAMESPACE + "getSmsFormWork",
				map, CommonBaseBean.class);

		return obj;
	}

	/**
	 * 
	 * @Description : 预警处理，信息查询
	 * @return
	 * @return JSONArray
	 * 
	 * @author : pengjy
	 * @throws ParseException
	 * @date : 2015年11月10日 下午5:09:57
	 * 
	 */
	public List<CommonBaseBean> queryWarnDealInfoByIdData(String userId,
			Map<String, String> params) throws ParseException {
		List<CommonBaseBean> rset = new ArrayList<CommonBaseBean>();
		// 查询数据
		List<CommonBaseBean> list = this.getBaseDao().queryForList(
				NAMESPACE + "queryWarnDealInfoById", params,
				CommonBaseBean.class);
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		// 权限过滤
		for (int i = 0; i < list.size(); i++) {
			String regionId = list.get(i).getQuery_value3();
			for (String aId : allList) {
				if (regionId.startsWith(aId)) {
					String timeStr = list.get(i).getQuery_value2();
					SimpleDateFormat datef = new SimpleDateFormat(
							"yyyyMMddHHmm");
					Date time = datef.parse(timeStr);
					Calendar calendar = Calendar.getInstance();
					calendar.setTime(time);
					String minStr = String.format("%02d",
							calendar.get(Calendar.MINUTE));
					String hour = String.format("%02d",
							calendar.get(Calendar.HOUR_OF_DAY));
					list.get(i).setQuery_value2(hour + "时" + minStr + "分");
					/*
					 * String stayPersonCnts = list.get(i).getQuery_value5();
					 * String areaValue = list.get(i).getQuery_value6(); if
					 * (stayPersonCnts.matches("[0-9]+") &&
					 * areaValue!=null&&!areaValue.endsWith("0")&&areaValue.
					 * endsWith("")) { double avg = 0; double num1 =
					 * Double.valueOf(stayPersonCnts); double num2 =
					 * Double.valueOf(areaValue); avg = num1/num2; DecimalFormat
					 * df = new DecimalFormat("#.##");
					 * list.get(i).setQuery_value5(df.format(avg)); }else {
					 * list.get(i).setQuery_value5("0"); }
					 */
					rset.add(list.get(i));
					break;
				}
			}
		}
		return rset;
	}

	/**
	 * 
	 * @Description : 查询预警处理记录信息
	 * 
	 * @return List
	 * 
	 * @author : menxl
	 * @date : 2015-11-20 下午3:02:16
	 * 
	 */
	public List<JSONObject> queryDealListByWarnId(String warnId) {
		// 查询数据
		List<JSONObject> rList = new ArrayList<JSONObject>();
		Map<String, String> params = new HashMap<String, String>();
		params.put("warnId", warnId);
		List<CommonBaseBean> dList = this.getBaseDao().queryForList(
				NAMESPACE + "queryDealListByWarnId", params,
				CommonBaseBean.class);
		if (null != dList && !dList.isEmpty()) {
			JSONObject j = null;
			// 拼接json
			for (CommonBaseBean bean : dList) {
				j = new JSONObject();

				String dealTypeId = bean.getQuery_value1();
				String dealTime = bean.getQuery_value2();
				String dealStaffId = bean.getQuery_value3();
				String receiveMsisdn = bean.getQuery_value4();
				String smsContent = bean.getQuery_value5();

				// 时间格式化
				dealTime = DateUtil.getInstance().dateFormat(dealTime,
						"yyyyMMddhhmmss", "yyyy-MM-dd hh:mm");

				j.put("dealTypeId", dealTypeId);
				j.put("dealTime", dealTime);
				j.put("dealStaffId", dealStaffId);
				j.put("receiveMsisdn", receiveMsisdn);
				j.put("smsContent", smsContent);

				rList.add(j);
			}
		}

		return rList;
	}

	/**
	 * @Description 插入告警信息处理短信表
	 * 
	 * @return Boolean
	 *
	 * @author : mi
	 * @date : 2015年11月14日 下午11:05:44
	 *
	 */
	public Boolean insertForWarnSmsMin(Map<String, String> params) {
		try {
			this.getBaseDao().delete(NAMESPACE + "insertForWarnSmsMin", params);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	/**
	 * 初始化景区列表
	 * 
	 * @author xiangzp 2016年7月4日11:32:07
	 */
	public void queryRegionList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String userId = inputObject.getParams().get("userId");
		List<JSONObject> rl = new ArrayList<JSONObject>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		List<CommonBaseBean> tList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionList", inputObject.getParams(),
				CommonBaseBean.class);
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		// 权限过滤
		if (tList == null) {
			tList = new ArrayList<CommonBaseBean>();
		}
		for (int i = 0; i < tList.size(); i++) {
			String regionId = tList.get(i).getQuery_value2();
			for (String aId : allList) {
				if (regionId.startsWith(aId)) {
					rList.add(tList.get(i));
					break;
				}
			}
		}
		if (rList.size() > 1) {
			CommonBaseBean bean = new CommonBaseBean();
			bean.setQuery_value1("");
			bean.setQuery_value2("");
			bean.setQuery_value3("全部");
			rList.add(0, bean);
		}
		if (rList != null && rList.size() > 0) {
			for (CommonBaseBean cbean : rList) {
				JSONObject obj = new JSONObject();
				obj.put("city_id", cbean.getQuery_value1());
				obj.put("region_id", cbean.getQuery_value2());
				obj.put("region_name", cbean.getQuery_value3());
				rl.add(obj);
			}
		}
		resultMap.put("regionData", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * 初始化city xiangzp 2016年7月4日14:59:59
	 */
	public void queryCityList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		String userId = inputObject.getParams().get("userId");
		List<JSONObject> rl = new ArrayList<JSONObject>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> rList = new ArrayList<CommonBaseBean>();
		List<CommonBaseBean> tList = this.getBaseDao().queryForList(
				NAMESPACE + "queryCityList", inputObject.getParams(),
				CommonBaseBean.class);
		// 数据权限
		Map<String, List<String>> scopeMap = commonService
				.queryUserScope(userId);
		List<String> allList = scopeMap.get(AreaBean.TYPE_ALL);
		// 权限过滤
		if (tList == null) {
			tList = new ArrayList<CommonBaseBean>();
		}
		for (int i = 0; i < tList.size(); i++) {
			String cityId = tList.get(i).getQuery_value1();
			for (String aId : allList) {
				if (cityId.startsWith(aId)) {
					rList.add(tList.get(i));
					break;
				}
			}
		}
		if (rList.size() > 1) {
			CommonBaseBean bean = new CommonBaseBean();
			bean.setQuery_value1("");
			bean.setQuery_value2("全省");
			rList.add(0, bean);
		}
		if (rList != null && rList.size() > 0) {
			for (CommonBaseBean cbean : rList) {
				JSONObject obj = new JSONObject();
				obj.put("city_id", cbean.getQuery_value1());
				obj.put("city_name", cbean.getQuery_value2());
				obj.put("core_longitude", cbean.getQuery_value3());
				obj.put("core_latitude", cbean.getQuery_value4());
				rl.add(obj);
			}
		}
		resultMap.put("cityData", null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}

	/**
	 * 
	 * 查询区域类型列表 xiangzp 2016年7月4日15:20:53
	 */
	public void queryRegionTypleList(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		List<JSONObject> rl = new ArrayList<JSONObject>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<CommonBaseBean> tList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionTypleList", inputObject.getParams(),
				CommonBaseBean.class);
		if (tList.size() > 1) {
			CommonBaseBean bean = new CommonBaseBean();
			bean.setQuery_value1("");
			bean.setQuery_value2("全部");
			tList.add(0, bean);
		}
		if (tList != null && tList.size() > 0) {
			for (CommonBaseBean cbean : tList) {
				JSONObject obj = new JSONObject();
				obj.put("region_type", cbean.getQuery_value1());
				obj.put("region_type_name", cbean.getQuery_value2());
				rl.add(obj);
			}
		}
		resultMap.put("regionTypeData",
				null == rl ? "" : JsonUtil.Object2Json(rl));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}
/**
	 * 
	 * 趋势分析 查询趋势分析数据 xiangzp 2016年7月4日17:01:33
	 * @throws ParseException 
	 */
	public void queryTrendChartsList(InputObject inputObject, OutputObject outputObject) throws BusinessException, ParseException {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		List<JSONObject> rl = new ArrayList<JSONObject>();
		List<JSONObject> rl2 = new ArrayList<JSONObject>();
		Map<String, Object> rmap = new HashMap<String, Object>();

		Map<String, String> params = new HashMap<String, String>();
		params = getParams(inputObject, outputObject);

		String startTime = params.get("startTime");		
		String endTime = params.get("endTime");
		String cycleId = params.get("cycleId");
		
		List<String> selectTimeList = new ArrayList<String>();
		
		if(cycleId=="hour" || "hour".equals(cycleId)){//获取所选日的时间点
			selectTimeList.add(startTime+"00");
			selectTimeList.add(startTime+"01");
			selectTimeList.add(startTime+"02");
			selectTimeList.add(startTime+"03");
			selectTimeList.add(startTime+"04");
			selectTimeList.add(startTime+"05");
			selectTimeList.add(startTime+"06");
			selectTimeList.add(startTime+"07");
			selectTimeList.add(startTime+"08");
			selectTimeList.add(startTime+"09");
			selectTimeList.add(startTime+"10");
			selectTimeList.add(startTime+"11");
			selectTimeList.add(startTime+"12");
			selectTimeList.add(startTime+"13");
			selectTimeList.add(startTime+"14");
			selectTimeList.add(startTime+"15");
			selectTimeList.add(startTime+"16");
			selectTimeList.add(startTime+"17");
			selectTimeList.add(startTime+"18");
			selectTimeList.add(startTime+"19");
			selectTimeList.add(startTime+"20");
			selectTimeList.add(startTime+"21");
			selectTimeList.add(startTime+"22");
			selectTimeList.add(startTime+"23");			
		}
		if(cycleId=="day" || "day".equals(cycleId)){//获取所选日期范围的所有日期
			Calendar startCalendar = Calendar.getInstance();
	        Calendar endCalendar = Calendar.getInstance();
	        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
	        Date startDate = df.parse(startTime);
	        startCalendar.setTime(startDate);
	        Date endDate = df.parse(endTime);
	        endCalendar.setTime(endDate);
	        
	        selectTimeList.add(startTime);//开始时间
	        while(true){
	            startCalendar.add(Calendar.DAY_OF_MONTH, 1);
	            if(startCalendar.getTimeInMillis() < endCalendar.getTimeInMillis()){
				selectTimeList.add(df.format(startCalendar.getTime()));	
		        }else{
		            break;
		        }
	        }
	        if(!startTime.equals(endTime)){
	        selectTimeList.add(endTime);//结束时间
	        }
		}
		if(cycleId=="month" || "month".equals(cycleId)){//获取所选月份范围内的所有月

			Calendar startCalendar = Calendar.getInstance();
	        Calendar endCalendar = Calendar.getInstance();
	        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
	        Date startDate = df.parse(startTime);
	        startCalendar.setTime(startDate);
	        Date endDate = df.parse(endTime);
	        endCalendar.setTime(endDate);
	        
	        selectTimeList.add(startTime);//开始时间
	        while(true){
	            startCalendar.add(Calendar.MONTH, 1);
	            if(startCalendar.getTimeInMillis() < endCalendar.getTimeInMillis()){
				selectTimeList.add(df.format(startCalendar.getTime()));	
		        }else{
		            break;
		        }
	        }
	        selectTimeList.add(endTime);//结束时间
		}
		
		
		List<CommonBaseBean> tList = this.getBaseDao().queryForList(
				NAMESPACE + "queryTrendChartsList", params,
				CommonBaseBean.class);
		if (tList != null && tList.size() > 0) {
			for (CommonBaseBean bean : tList) {
				JSONObject obj = new JSONObject();					
				obj.put("countName", bean.getQuery_value1());
				obj.put("countValue", bean.getQuery_value2());
				rl.add(obj);
			}
		}
		//表中不存在所选日期数据时，造相应日期数据
		if(rl.size()>0){
			for(int j=0;j<selectTimeList.size();j++){
				int flag=0;
				for(int k=0;k<rl.size();k++){
					if(selectTimeList.get(j) == rl.get(k).getString("countName") || selectTimeList.get(j).equals(rl.get(k).getString("countName"))){
						JSONObject obj = new JSONObject();					
						obj.put("countName",rl.get(k).getString("countName"));
						obj.put("countValue", rl.get(k).getString("countValue"));
						rl2.add(obj);
						flag=1;
					}
					
				}
				if(flag==0){
					JSONObject obj = new JSONObject();					
					obj.put("countName",selectTimeList.get(j));
					obj.put("countValue",'0');
					rl2.add(obj);
				}
			}
		}
		if(rl.size()==0 && "day".equals(cycleId)){
			for(int j=0;j<selectTimeList.size();j++){
				int flag=0;
				for(int k=0;k<rl.size();k++){
					if(selectTimeList.get(j) == rl.get(k).getString("countName") || selectTimeList.get(j).equals(rl.get(k).getString("countName"))){
						JSONObject obj = new JSONObject();					
						obj.put("countName",rl.get(k).getString("countName"));
						obj.put("countValue", rl.get(k).getString("countValue"));
						rl2.add(obj);
						flag=1;
					}
					
				}
				if(flag==0){
					JSONObject obj = new JSONObject();					
					obj.put("countName",selectTimeList.get(j));
					obj.put("countValue",'0');
					rl2.add(obj);
				}
			}
		}
		

		rmap.put("type",null == params ? "" : params.get("cycleId"));
		rmap.put("chartList",null == rl2 ? "" : JsonUtil.Object2Json(rl2));
		JSONObject data = JSONObject.fromObject(rmap);
		resultMap.put("data", null == data ? "" : JsonUtil.Object2Json(data));
		outputObject.setObject(JsonUtil.Object2Json(resultMap));
	}
	/**
	 * 
	 * 导出趋势分析数据 xiangzp 2016年7月9日11:04:03
	 * @throws ParseException 
	 */
	public void dlTrendChartsList(InputObject inputObject, OutputObject outputObject) throws BusinessException, ParseException {
		Map<String,String> params = new HashMap<String,String>();
		params = getParams(inputObject,outputObject);

		
		String startTime = params.get("startTime");		
		String endTime = params.get("endTime");
		String cycleId = params.get("cycleId");
		
		List<String> selectTimeList = new ArrayList<String>();
		
		if(cycleId=="hour" || "hour".equals(cycleId)){//获取所选日的时间点
			selectTimeList.add(startTime+"00");
			selectTimeList.add(startTime+"01");
			selectTimeList.add(startTime+"02");
			selectTimeList.add(startTime+"03");
			selectTimeList.add(startTime+"04");
			selectTimeList.add(startTime+"05");
			selectTimeList.add(startTime+"06");
			selectTimeList.add(startTime+"07");
			selectTimeList.add(startTime+"08");
			selectTimeList.add(startTime+"09");
			selectTimeList.add(startTime+"10");
			selectTimeList.add(startTime+"11");
			selectTimeList.add(startTime+"12");
			selectTimeList.add(startTime+"13");
			selectTimeList.add(startTime+"14");
			selectTimeList.add(startTime+"15");
			selectTimeList.add(startTime+"16");
			selectTimeList.add(startTime+"17");
			selectTimeList.add(startTime+"18");
			selectTimeList.add(startTime+"19");
			selectTimeList.add(startTime+"20");
			selectTimeList.add(startTime+"21");
			selectTimeList.add(startTime+"22");
			selectTimeList.add(startTime+"23");			
		}
		if(cycleId=="day" || "day".equals(cycleId)){//获取所选日期范围的所有日期
			Calendar startCalendar = Calendar.getInstance();
	        Calendar endCalendar = Calendar.getInstance();
	        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
	        Date startDate = df.parse(startTime);
	        startCalendar.setTime(startDate);
	        Date endDate = df.parse(endTime);
	        endCalendar.setTime(endDate);
	        
	        selectTimeList.add(startTime);//开始时间
	        while(true){
	            startCalendar.add(Calendar.DAY_OF_MONTH, 1);
	            if(startCalendar.getTimeInMillis() < endCalendar.getTimeInMillis()){
				selectTimeList.add(df.format(startCalendar.getTime()));	
		        }else{
		            break;
		        }
	        }
	        if(!startTime.equals(endTime)){
	        selectTimeList.add(endTime);//结束时间
	        }
		}
		if(cycleId=="month" || "month".equals(cycleId)){//获取所选月份范围内的所有月

			Calendar startCalendar = Calendar.getInstance();
	        Calendar endCalendar = Calendar.getInstance();
	        SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
	        Date startDate = df.parse(startTime);
	        startCalendar.setTime(startDate);
	        Date endDate = df.parse(endTime);
	        endCalendar.setTime(endDate);
	        
	        selectTimeList.add(startTime);//开始时间
	        while(true){
	            startCalendar.add(Calendar.MONTH, 1);
	            if(startCalendar.getTimeInMillis() < endCalendar.getTimeInMillis()){
				selectTimeList.add(df.format(startCalendar.getTime()));	
		        }else{
		            break;
		        }
	        }
	        selectTimeList.add(endTime);//结束时间
		}
		
		
		
		List<CommonBaseBean> tList = this.getBaseDao().queryForList(
				NAMESPACE+"queryTrendChartsList", params,CommonBaseBean.class);
		List<Map<String,Object>> dataList = new ArrayList<Map<String,Object>>();
		List<Map<String,Object>> dataList2 = new ArrayList<Map<String,Object>>();
		for(CommonBaseBean cBean : tList){

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("countName", cBean.getQuery_value1());
			map.put("countValue", cBean.getQuery_value2());
			dataList.add(map);
		}
		
		//表中不存在所选日期数据时，造相应日期数据
		if(dataList.size()>0){
			for(int j=0;j<selectTimeList.size();j++){
				int flag=0;
				for(int k=0;k<dataList.size();k++){
					if(selectTimeList.get(j) == dataList.get(k).get("countName") || selectTimeList.get(j).equals(dataList.get(k).get("countName"))){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("countName",dataList.get(k).get("countName"));
						map.put("countValue", dataList.get(k).get("countValue"));
						dataList2.add(map);
						flag=1;
					}
					
				}
				if(flag==0){
					Map<String, Object> map = new HashMap<String, Object>();			
					map.put("countName",selectTimeList.get(j));
					map.put("countValue",'0');
					dataList2.add(map);
				}
			}
		}
		
		if(dataList.size()==0 && "day".equals(cycleId)){
			for(int j=0;j<selectTimeList.size();j++){
				int flag=0;
				for(int k=0;k<dataList.size();k++){
					if(selectTimeList.get(j) == dataList.get(k).get("countName") || selectTimeList.get(j).equals(dataList.get(k).get("countName"))){
						Map<String, Object> map = new HashMap<String, Object>();
						map.put("countName",dataList.get(k).get("countName"));
						map.put("countValue", dataList.get(k).get("countValue"));
						dataList2.add(map);
						flag=1;
					}
					
				}
				if(flag==0){
					Map<String, Object> map = new HashMap<String, Object>();			
					map.put("countName",selectTimeList.get(j));
					map.put("countValue",'0');
					dataList2.add(map);
				}
			}
		}
			
		String rowNum = "2";
		String title = "数据时间::客流人数";
		String fileName = createDownloadFileName("趋势分析", params);
		String sheetName = "趋势分析";
		String expType = "1";

		ExportBean export = new ExportBean(rowNum, title, fileName, sheetName, expType, dataList2);
//		JSONObject json = JSONObject.fromObject(export);
		outputObject.setObject(export);
	}

	/**
	 * 获取查询条件 xiangzp
	 */
	public Map<String, String> getParams(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("cityId", inputObject.getParams().get("cityId"));
		map.put("regionType", inputObject.getParams().get("regionType"));
		map.put("regionId", inputObject.getParams().get("regionId"));
		String cycleId = inputObject.getParams().get("cycleId");
		if (cycleId == null || "".equals(cycleId)) {
			cycleId = "day";
		}
		map.put("cycleId", cycleId);
		String startTime = inputObject.getParams().get("startTime");
		if (null != startTime && !"".equals(startTime)) {
			startTime = startTime.replaceAll("-", "");
		}
		map.put("startTime", startTime);
		String endTime = inputObject.getParams().get("endTime");
		if (null != endTime && !"".equals(endTime)) {
			endTime = endTime.replaceAll("-", "");
		}
		map.put("endTime", endTime);
		Map<String, String> params = getDefaultDate(map);
		return params;
	}

	/**
	 * 设置查询日期默认值
	 * 
	 * @param params
	 * @return
	 */
	public Map<String, String> getDefaultDate(Map<String, String> params) {
		String cycleType = params.get("cycleId");
		String startTime = params.get("startTime");
		String endTime = params.get("endTime");
		if ("hour".equals(cycleType)) {
			if (null == startTime || "".equals(startTime)) {
				String dayStr = DateUtil.getInstance().getToday("yyyyMMdd");
				params.put("startTime", dayStr);
				params.put("endTime", dayStr);
			} else {
				params.put("endTime", startTime);
			}
		} else if ("day".equals(cycleType)) {
			String dayStr = DateUtil.getInstance().getYesterday(DateUtil.getInstance().getToday("yyyyMMdd"),"yyyyMMdd");
			if (null == startTime || "".equals(startTime)) {
				params.put("startTime", dayStr);
			}
			if (null == endTime || "".equals(endTime)) {
				String endStr = DateUtil.getInstance().getXDay(dayStr,
						"yyyyMMdd",-29);
				params.put("startTime", endStr);
				params.put("endTime", dayStr);
			}
		} else if ("month".equals(cycleType)) {
			String todayStr = DateUtil.getInstance().getToday("yyyyMMdd");
			String monthEnd = DateUtil.getInstance().getLastMonth(todayStr,
					"yyyyMMdd");
			monthEnd = monthEnd.substring(0, 6);
			String monthStart = DateUtil.getInstance().getOtherMonth(todayStr,
					"yyyyMMdd", -12);
			monthStart = monthStart.substring(0, 6);
			params.put("startTime", monthStart);
			params.put("endTime", monthEnd);
		}
		return params;
	}


	/**
	 * @Description : 生成下载文件名称
	 * 
	 * @return String 文件名
	 *
	 * @author : xuxiong
	 * @date : 2015年12月24日 下午3:36:07
	 * 
	 */
	private String createDownloadFileName(String functionName,
			Map<String, String> params) {
		StringBuilder fileName = new StringBuilder();
		fileName.append(functionName);

		Map<String, AreaBean> cityMap = AreaCache.areaCache
				.get(AreaBean.TYPE_CITY);
		Map<String, AreaBean> regionMap = AreaCache.areaCache
				.get(AreaBean.TYPE_REGION);

		String cityId = params.get("cityId");
		if (StringUtils.isNotBlank(cityId)) {
			fileName.append("_").append(cityMap.get(cityId).getAreaName());
		} else {
			fileName.append("_全省");
		}

		String regionType = params.get("regionType");
		if (StringUtils.isNotBlank(regionType)) {
			fileName.append("_").append(regionType).append("A");
		} else {
			fileName.append("_全部类型");
		}

		String regionId = params.get("regionId");
		if (StringUtils.isNotBlank(regionId)) {
			fileName.append("_").append(regionMap.get(regionId).getAreaName());
		} else {
			fileName.append("_全部景区");
		}

		String startTime = params.get("startTime");
		if (StringUtils.isNotBlank(startTime)) {
			fileName.append("_").append(startTime);
		}

		String endTime = params.get("endTime");
		if (StringUtils.isNotBlank(endTime) && !startTime.equals(endTime)) {
			fileName.append("-").append(endTime);
		}

		return fileName.toString();
	}

	/**
	 * 查询摄像头信息
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	@Override
	public void queryCamera(InputObject inputObject, OutputObject outputObject)
			throws BusinessException {

		List<CommonBaseBean> allList = this.getBaseDao().queryForList(
				NAMESPACE + "queryCamera", inputObject.getParams(),
				CommonBaseBean.class);
		if (allList == null) {
			allList = new ArrayList<CommonBaseBean>();
		}
		JSONArray jArr = new JSONArray();
		JSONObject j = new JSONObject();
		for (CommonBaseBean bean : allList) {
			if (bean != null) {
				j.put("cameraId", bean.getQuery_value1());
				j.put("longitude", bean.getQuery_value2());
				j.put("latitude", bean.getQuery_value3());
				j.put("ipAddress", bean.getQuery_value4());
				j.put("addressDesc", bean.getQuery_value5());
				j.put("status", bean.getQuery_value5());
				jArr.add(j);
			}
		}
		outputObject.setObject(JsonUtil.Object2Json(jArr));
	}

	/**
	 * 客流预测
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	@Override
	public void trendForecast(InputObject inputObject,
			OutputObject outputObject) throws BusinessException {

		Date today = new Date();
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(today);
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");

		inputObject.getParams().put("stateDate", df.format(today));
		List<CommonBaseBean> allList = this.getBaseDao().queryForList(
				NAMESPACE + "trendForecast", inputObject.getParams(),
				CommonBaseBean.class);
		if (allList == null) {
			allList = new ArrayList<CommonBaseBean>();
		}
		JSONArray jArr = new JSONArray();
		JSONObject j = new JSONObject();

		for (int i = 0; i < allList.size() && i < 7; i++) {
			CommonBaseBean bean = allList.get(i);
			calendar.add(Calendar.DAY_OF_MONTH, +1);
			String tmpDateStr = df.format(calendar.getTime());
			if (bean != null && tmpDateStr.equals(bean.getQuery_value2())) {
				j.put("stateDate", bean.getQuery_value1());
				j.put("forecastDate", bean.getQuery_value2());
				j.put("cityId", bean.getQuery_value3());
				j.put("regionId", bean.getQuery_value4());
				j.put("vstPersonCnts", bean.getQuery_value5());
				jArr.add(j);
			} else {
				j.put("stateDate", bean.getQuery_value1());
				j.put("forecastDate", tmpDateStr);
				j.put("cityId", bean.getQuery_value3());
				j.put("regionId", bean.getQuery_value4());
				j.put("vstPersonCnts", 0);
				jArr.add(j);
			}
		}
		outputObject.setObject(JsonUtil.Object2Json(jArr));
	}

	/**
	 * 根据景区ID查询景区舒适度信息
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	@Override
	public void queryComfortLevel(InputObject inputObject, OutputObject outputObject)
			throws BusinessException {

		List<CommonBaseBean> allList = this.getBaseDao().queryForList(
				NAMESPACE + "queryComfortLevel", inputObject.getParams(),
				CommonBaseBean.class);
		if (allList == null) {
			allList = new ArrayList<CommonBaseBean>();
		}
		JSONArray jArr = new JSONArray();
		JSONObject j = new JSONObject();
		for (CommonBaseBean bean : allList) {
			if (bean != null) {
				j.put("op_time", bean.getQuery_value1());
				j.put("region_id", bean.getQuery_value2());
				j.put("comfortable_level", bean.getQuery_value3());
				j.put("temper_level", bean.getQuery_value4());
				j.put("contamin_level", bean.getQuery_value5());
				j.put("weather_level", bean.getQuery_value6());
				j.put("tourism_com_level", bean.getQuery_value7());
				j.put("density_level", bean.getQuery_value8());
				j.put("comfortable_level_desc", bean.getQuery_value9());
				jArr.add(j);
			}
		}
		outputObject.setObject(JsonUtil.Object2Json(jArr));
	}	
	
	/**
	 * 查询所有景区舒适度信息
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 */
	@Override
	public void queryRegionComfortList(InputObject inputObject, OutputObject outputObject)
			throws BusinessException {

		List<CommonBaseBean> allList = this.getBaseDao().queryForList(
				NAMESPACE + "queryRegionComfortList", inputObject.getParams(),
				CommonBaseBean.class);
		if (allList == null) {
			allList = new ArrayList<CommonBaseBean>();
		}
		JSONArray jArr = new JSONArray();
		JSONObject j = new JSONObject();
		for (CommonBaseBean bean : allList) {
			if (bean != null) {
				//j.put("op_time", bean.getQuery_value1());
				j.put("city_id", bean.getQuery_value2());
				j.put("region_type", bean.getQuery_value3());
				j.put("region_id", bean.getQuery_value4());
				j.put("region_name", bean.getQuery_value5());
				j.put("comfortable_level", bean.getQuery_value6());
				jArr.add(j);
			}
		}
		outputObject.setObject(JsonUtil.Object2Json(jArr));
	}
	
	/**
	 * 根据景区ID查询景区舒适度信息
	 * 
	 * @param inputObject
	 * @param outputObject
	 * @throws BusinessException
	 * @throws SQLException 
	 * @throws IOException 
	 */
	@Override
	public void queryRegionImage(InputObject inputObject, OutputObject outputObject)
	throws BusinessException {

		JSONArray jArr = new JSONArray();
		JSONObject j = new JSONObject();
		//用vertica的varbinary(65000)字段，存储base64编码的图片（图片编码长度要小于65000字节），读取时为16进制编码，需要转为字符串
		if ("vertica".equals(InitParam.DB_TYPE)) {
			List<CommonBaseBean> allList = this.getBaseDao().queryForList(
					NAMESPACE + "queryRegionImage", inputObject.getParams(),
					CommonBaseBean.class);
			if (allList == null) {
				allList = new ArrayList<CommonBaseBean>();
			}
			for (CommonBaseBean bean : allList) {
				if (bean != null) {
					j.put("region_id", bean.getQuery_value1());
					j.put("photo_type", bean.getQuery_value2());
					j.put("photo_type_name", bean.getQuery_value3());
					j.put("IMG_BASE64_CODE", hexStringToString(bean.getQuery_value4()));//vertica 存储的图片编码为16进制，需转为正常字符串
					jArr.add(j);
				}
			}
		}
		//用oracle的blob字段存储base64编码的图片时，需要将blob字段转为字符串,使用方法blob2Str()
		else if ("oracle".equals(InitParam.DB_TYPE)) {
			List<Map<String, Object>> allList=null;			
			allList = this.getBaseDao().queryForListObj(NAMESPACE + "queryRegionImageForOracle", inputObject.getParams());
			if (allList == null) {
				allList = new ArrayList<Map<String, Object>>();
			}
			for( int i=0;i<allList.size();i++){
				if (allList.get(i) != null) {				
					j.put("region_id", allList.get(i).get("QUERY_VALUE1"));
					j.put("photo_type", allList.get(i).get("QUERY_VALUE2"));
					j.put("photo_type_name", allList.get(i).get("QUERY_VALUE3"));
					Object IMG_BASE64_CODE=allList.get(i).get("QUERY_VALUE4");
					Blob blob = (Blob) IMG_BASE64_CODE;
					try {
						String img_code= blob2Str(blob);
						//缩略图
						img_code = Base64ImgUtil.base64ImgCompress(221,137, img_code);
						j.put("IMG_BASE64_CODE",img_code==null?"":img_code);
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					jArr.add(j);
				}
			}
		}
		//其他数据库存储base64编码时，暂认为能直接获取到实际编码值的字符串
		else {
			List<CommonBaseBean> allList = this.getBaseDao().queryForList(
					NAMESPACE + "queryRegionImage", inputObject.getParams(),
					CommonBaseBean.class);
			if (allList == null) {
				allList = new ArrayList<CommonBaseBean>();
			}
			for (CommonBaseBean bean : allList) {
				if (bean != null) {
					j.put("region_id", bean.getQuery_value1());
					j.put("photo_type", bean.getQuery_value2());
					j.put("photo_type_name", bean.getQuery_value3());
					j.put("IMG_BASE64_CODE", bean.getQuery_value4());//base64的实际编码值能正常读取
					jArr.add(j);
				}
			}
		}		
		outputObject.setObject(JsonUtil.Object2Json(jArr));
	}	
}
